package cn.tedu.start.controller.customer;

import cn.tedu.commons.response.JsonResult;
import cn.tedu.pojo.customer.dto.CustomerAddrDTO;
import cn.tedu.pojo.customer.entity.CustomerInf;
import cn.tedu.pojo.customer.entity.CustomerLogin;
import cn.tedu.pojo.customer.vo.CustomerAddrVO;
import cn.tedu.pojo.customer.vo.CustomerInfVO;
import cn.tedu.service.customer.ICustomerAddrService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/customer/addr")
@RestController
public class CustomerAddrController<T> {
    @Autowired
    private  ICustomerAddrService iCustomerAddrService;


    //下面方法还没实现
   /* @ApiOperation("根据用户名查询用户地址")
    @PostMapping("/selectAddrByName")

    public  JsonResult<CustomerAddrVO> getAddrByUserName(String userName){
    return null;
    }*/

    @ApiOperation("根据用户id查询地址")
    @PostMapping("/selectAddrById")
    @ApiImplicitParam(name = "userId",required = true,paramType = "path",dataType = "Long")
    public JsonResult<CustomerAddrVO>  getAddrByUserId (Long userId){
        return JsonResult.ok(iCustomerAddrService.getAddrByUserId(userId));
    }

    @ApiOperation("更改地址")
    @PostMapping("/updateAddr")
    public  JsonResult updateAddr(CustomerAddrDTO customerAddrDTO){
        return JsonResult.ok(iCustomerAddrService.updateAddr(customerAddrDTO));

    }

    @ApiOperation("查询地址")
    @PostMapping("/selectByOldAddr")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId",required = true,paramType = "path",dataType = "Long"),
            @ApiImplicitParam(name = "userAddr",required = true,paramType = "path",dataType = "String")})
    public JsonResult<CustomerAddrVO> getAddrByOldAddr(Long userId,String userAddr){
        return JsonResult.ok(iCustomerAddrService.getAddrByOldAddr(userId,userAddr));
    }

    @ApiOperation("根据delete查询地址")
    @PostMapping("/selectByDelete")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId",required = true,paramType = "path",dataType = "Long"),
            @ApiImplicitParam(name = "isDelete",required = true,paramType = "path",dataType = "Integer")})
    public  JsonResult<CustomerAddrVO> getAddrByDelete (Long userId,Integer isDelete){
        return JsonResult.ok(iCustomerAddrService.getAddrByDelete(userId,isDelete));
    }

    @ApiOperation("根据 delete查询用户信息")
    @PostMapping("/select/addr-delete")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId",required = true,paramType = "path",dataType = "Long"),
            @ApiImplicitParam(name = "isDelete",required = true,paramType = "path",dataType = "Integer")})
    public  JsonResult<CustomerAddrVO> updateAddrDelete(Long userId,Integer isDelete){
        CustomerAddrVO AddrVO = iCustomerAddrService.updateAddDelete(userId, isDelete);
        return JsonResult.ok(AddrVO);
    }

    @ApiOperation("查询所有用户地址信息")
    @PostMapping("/select/all-addr")
    public  JsonResult<List<CustomerAddrVO>> list(){
        List<CustomerAddrVO> list = iCustomerAddrService.list();
        return JsonResult.ok(list);
    }


}
